package com.chat.controller;

import com.chat.domain.dto.auth.LoginDTO;
import com.chat.domain.dto.user.UserRegisterDTO;
import com.chat.service.AuthService;
import com.chat.util.Result;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 认证控制器
 *
 * @author wb
 * @since 2025-06-06
 */

@RequestMapping("auth")
@RestController
public class AuthController {

    @Autowired
    private AuthService authService;

    @PostMapping("/login")
    public Result<Boolean> login(@Valid LoginDTO loginDTO, HttpSession session) {
        return authService.login(loginDTO, session) ? Result.ok() : Result.fail();
    }


    @PostMapping("/register")
    public Result<Boolean> register(@Valid UserRegisterDTO userRegisterDTO) {
        return authService.register(userRegisterDTO) ? Result.ok() : Result.fail();
    }

}
